public class Test6 {
    private static  final  long count =10_0000_0000;
    public  static void serial(){
        // 记录程序自增开始的时间
        long begin = System.currentTimeMillis();
        long a = 0;
        for(long i = 0;i < count;i++){
            a++;
        }
        long b = 0;
        for (long i = 0; i < count; i++) {
            b++;
        }
        // 记录自增程序结束时间。
        long end = System.currentTimeMillis();
        System.out.println("花费的时间："+ (end - begin) + "ms");
    }

    public static void concurrency() throws InterruptedException {
        long begin = System.currentTimeMillis();
        Thread t1 = new Thread(()->{
           long a = 0;
            for (long i = 0; i < count; i++) {
                a++;
            }
        });
        t1.start();
        Thread t2 = new Thread(()->{
           long b = 0;
           for(long i = 0;i < count;i++){
               b++;
           }
        });
        t2.start();

        // join 效果 就是等待线程结束。
        t1.join();// 让 main线程 等待 t1 线程执行结束
        t2.join();// 让 main线程 等待 t2 线程执行结束
        long end = System.currentTimeMillis();
        System.out.println("花费时间：" + (end - begin));
    }

    public static void main(String[] args) throws InterruptedException {
        serial();
        concurrency();
    }
}
